﻿Public Class Form2
    ''' <summary>
    ''' FORM2.
    ''' Listbox1 = Lists found Files and Directories.
    ''' Listbox2 = Lists details about what is found.
    ''' lblMessage = Label to display Viruses Found or not found.  Text is red if found, green if nothing found.
    ''' Button1 = Clean viruses.
    ''' ProgressBar1 = Progress of Cleaning. TO DO.
    ''' VirusCount = Will be used for ProgressBar1.
    ''' </summary>
    ''' <remarks></remarks>
    Dim VirusCount As Integer = 0

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Make sure listboxes are cleared before anything is added.
        ListBox1.Items.Clear()
        ListBox2.Items.Clear()

        ' How many total items found, used for progress bar.
        VirusCount = Form1.FoundFiles.Count + Form1.FoundDirs.Count

        ' Get list of any items from Arrays "FoundFiles" and "FoundDirs"
        If Form1.FoundDirs.Count Or Form1.FoundFiles.Count > 0 Then
            For i = 0 To Form1.FoundDirs.Count - 1
                ListBox1.Items.Add(Form1.FoundDirs(i))
            Next

            For i = 0 To Form1.FoundFiles.Count - 1
                ListBox1.Items.Add(Form1.FoundFiles(i))
            Next

            ' Enable "Clean" button if there are any virses, otherwise leave disabled and show appropiate mesage.
            Label3.ForeColor = Color.Red
            Label3.Text = "Your computer is a major risk, Anti-Virus suggests you clean the spotted viruses"
            Button1.Enabled = True
        Else
            Label3.ForeColor = Color.Green
            Label3.Text = "No viruses found. Your computer is clean."
            Button1.Enabled = False
        End If

        ' Add to Listbox 2, depending on what form1.combobox selection.
        Select Case Form1.ComboBox1.SelectedIndex
            Case 0 ' Viruses.
                ListBox2.Items.Add("Viruses Found " & Form1.VirusesFound)
            Case 1 ' Spyware.
                ListBox2.Items.Add("Spyware Found " & Form1.SpywareFound)
            Case 2 ' Adware.
                ListBox2.Items.Add("Adware Found " & Form1.AdwareFound)
        End Select
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Clean Button.
        Try
            ' Delete Directories.
            For i = 0 To Form1.FoundDirs.Count - 1
                IO.Directory.Delete(Form1.FoundDirs(i))
            Next

            For i = 0 To Form1.FoundFiles.Count - 1
                IO.File.Delete(Form1.FoundFiles(i))
            Next
            ' Files and Directories have been deleted.
            MessageBox.Show("Your computer has been Cleaned", "Successs", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            ' Any errors, like cant delete a file - show here.
            MessageBox.Show(ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Form1.Show()
    End Sub
End Class